package com.git.hui.yinshua.biz.pay.service.wx;

import com.git.hui.yinshua.biz.pay.dao.entity.OrderPaymentEntity;
import com.git.hui.yinshua.biz.pay.dao.entity.OrderRefundEntity;
import com.git.hui.yinshua.biz.pay.model.PreOrderDynamicParam;
import com.git.hui.yinshua.biz.rest.models.order.rsp.PrePayInfoDo;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.Refund;
import com.wechat.pay.java.service.refund.model.RefundNotification;
import jdk.nashorn.internal.ir.FunctionNode;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.function.Function;

/**
 * 微信支付
 */
public interface IWxPayService {
    /**
     * JSAPI下单
     *
     * @return
     */
    PrePayInfoDo jsApiOrder(PreOrderDynamicParam preOrderDynamicParam) throws Exception;

    /**
     * 构建前端唤醒支付的相关信息
     *
     * @param prePayId
     * @param outTradeNo
     * @return
     * @throws Exception
     */
    PrePayInfoDo genToPayPrePayInfo(String prePayId, String outTradeNo);

    /**
     * 支付回调
     *
     * @param request
     * @return
     * @throws IOException
     */
    ResponseEntity callback(HttpServletRequest request, Function<Transaction, Boolean> payCallback) throws IOException;

    /**
     * 查询订单，根据商户订单号
     *
     * @return
     */
    Transaction queryWxPayOrderOutTradeNo(String transNo);

    /**
     * 关闭订单
     *
     * @return
     */
    void closePay(String outTradeNo);


    /**
     * 申请退款
     *
     * @param refund
     * @param payAmount
     * @return
     */
    Refund refund(OrderRefundEntity refund, Integer payAmount, String outTradeNo);


    ResponseEntity refundCallback(HttpServletRequest request, Function<RefundNotification, Boolean> refundCallback) throws IOException;
}
